
const {searchGoodsSell,getGoodsecharts, getGoodsByPageSell, deleteGoodsSell, getGoodsId,
     updateGoodsSell, searchAllGoodsSell, getAllGoodsByPageSell, deleteGoods,puton,
     searchGoodsUnsold,getGoodsByPageUnsold,searchGoodsOut,getGoodsByPageOut,getGoods } = require("../dao/goodsDao");

/**
 * ++++++++++++++++++++++++++++++++++李兴乾+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
//渲染上架商品---lxq
module.exports.getGoodsSell = async function (goods) {
    console.log(2222222222,goods)
    if (goods.searchValue && goods.state == "上架") {
        return await searchGoodsSell(goods)
    } else if (goods.pageSize && goods.state == "上架") {
        return await getGoodsByPageSell(goods)
    } else if (goods.state == "全部" && goods.searchType) {
        return await searchAllGoodsSell(goods)
    } else if (goods.state == "全部" && goods.pageSize) {
        return await getAllGoodsByPageSell(goods)
    }else if(goods.searchType && goods.state == "库存"){
        return await searchGoodsUnsold(goods)
    } else if (goods.pageSize && goods.state == "库存") {
        return await getGoodsByPageUnsold(goods)
    }else if(goods.searchType && goods.state == "下架"){
        return await searchGoodsOut(goods)
    } else if (goods.pageSize && goods.state == "下架") {
        return await getGoodsByPageOut(goods)
    }
};
//下架商品
module.exports.deleteGoodsSell = async function (goods) {
    const data = await deleteGoodsSell(goods)
    if (data.ok == 1) {
        return true
    } else {
        return false
    }
}
//通过id查找商品getGoodsId
module.exports.getGoodsId = async function (goods) {
    return await getGoodsId(goods)
}

// module.exports.getGoods = async function (goods) {
//     return await getGoods(goods)
// }
//获取所有商品
module.exports.getGoodsecharts = async function (goods) {
    return await getGoodsecharts(goods)
}
//修改上架商品
module.exports.updateGoodsSell = async function (goods) {
    return await updateGoodsSell(goods)
}


//删除库存商品
module.exports.deleteGoods = async function (_id) {
    const data = await deleteGoods(_id)
    if (data.ok == 1) {
        return true
    } else {
        return false
    }
}

/**
 * ++++++++++++++++++++++++++++++++++刘磊+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */

// 添加商品
module.exports.addGoods = async function (good){
    // console.log(good);
    
    const data =  await addGoods(good)
    if(data._id){
        return true
    }
    return false
};

//上架
module.exports.puton = async function (goods) {
    return await puton(goods)
}

//===============================徐芊===========================================================
//获取全部商品
module.exports.getGoods = async function (goods){
    console.info(goods)
    const data =  await getGoods(goods)
   return data
};
  //===============================徐芊===========================================================
  





